package com.fj.netty.chat.message;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * @author fj
 * @date 2024/1/11 14:29
 */
public abstract class Message implements Serializable {
    /**
     * 序列号
     */
    private Integer sequenceId;

    public Integer getSequenceId() {
        return sequenceId;
    }

    public void setSequenceId(Integer sequenceId) {
        this.sequenceId = sequenceId;
    }


    public static final byte LOGIN_REQUEST_MESSAGE = 1;
    public static final byte CHAT_REQUEST_MESSAGE = 2;
    public static final byte GROUP_CHAT_REQUEST_MESSAGE = 3;
    public static final byte GROUP_CREATE_REQUEST_MESSAGE = 4;
    public static final byte GROUP_MEMBERS_REQUEST_MESSAGE = 5;
    public static final byte GROUP_JOIN_REQUEST_MESSAGE = 6;
    public static final byte GROUP_QUIT_REQUEST_MESSAGE = 7;
    public static final byte GROUP_CHAT_RESPONSE_MESSAGE = 8;
    public static final byte GROUP_MEMBERS_RESPONSE_MESSAGE = 9;
    public static final byte PING_REQUEST_MESSAGE = 10;
    public static final byte LOGIN_RESPONSE_MESSAGE = 11;
    public abstract byte getMessageType();

    private static final Map<Byte,Class<? extends Message>> messageTypeMap = new HashMap<>(10);

    static {
        messageTypeMap.put(LOGIN_REQUEST_MESSAGE,LoginRequestMessage.class);
        messageTypeMap.put(CHAT_REQUEST_MESSAGE, ChatRequestMessage.class);
        messageTypeMap.put(GROUP_CHAT_REQUEST_MESSAGE, GroupChatRequestMessage.class);
        messageTypeMap.put(GROUP_CREATE_REQUEST_MESSAGE,GroupCreateRequestMessage.class);
        messageTypeMap.put(GROUP_MEMBERS_REQUEST_MESSAGE,GroupMembersRequestMessage.class);
        messageTypeMap.put(GROUP_JOIN_REQUEST_MESSAGE,GroupJoinRequestMessage.class);
        messageTypeMap.put(GROUP_QUIT_REQUEST_MESSAGE,GroupQuitRequestMessage.class);
        messageTypeMap.put(GROUP_CHAT_RESPONSE_MESSAGE,GroupChatResponseMessage.class);
        messageTypeMap.put(GROUP_MEMBERS_RESPONSE_MESSAGE,GroupMembersResponseMessage.class);
        messageTypeMap.put(PING_REQUEST_MESSAGE,PingRequestMessage.class);
        messageTypeMap.put(LOGIN_RESPONSE_MESSAGE,LoginResponseMessage.class);
    }

    public static Class<? extends Message> getMessageClass(Byte messageType){
        return Message.messageTypeMap.get(messageType);
    }
}
